home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Lanstar - EdOptFuncts
- ** Aztec C compiler 1.06h
- ** Lightspeed C compiler 1.02
- **
- ** David A. Surovell
- ** 21-Dec-86
- */
-
- #include <extender.h>
- #include <extend2.h>
- #include <EdOpts.h>
-
- WindowPtr edoptWP;
- WindowRecord edoptWR;
- ControlHandle edoptWPB1,edoptWPB2;
- ListHandle fontList,stylList,sizeList,justList;
-
- int TESizes[] = {9,10,12,14,18,24,36};
-
-
- Boolean InitEdOpts()
- {
- Rect aRect;
- Boolean stat;
-
- SetRect(&aRect,20,50,470,200);
- edoptWP = CreateWindow(&edoptWR,&aRect,"\PEditing options",4,
- FALSE,FALSE,FALSE,FALSE,FALSE);
- TextFont(newYork);
- SetException(edoptWP,EXCPTupdate,TRUE);
-
- stat = BuildEOLists(edoptWP);
-
- SetRect(&aRect,280,110,340,130);
- edoptWPB1 = CreatePushButton(edoptWP,&aRect,"\POK");
- SetRect(&aRect,350,110,410,130);
- edoptWPB2 = CreatePushButton(edoptWP,&aRect,"\PCANCEL");
- DrawControls(edoptWP);
-
- return(stat);
- }
-
-
- Boolean BuildEOLists(wPtr)
- WindowPtr wPtr;
- {
- MenuHandle dummyMH;
- ListHandle *theLHP;
- Point lOffset,cSize;
- int iCount,rowsVis,i;
- Boolean stat;
-
- for (i=0; i<4; i++) {
- dummyMH = NewMenu(UniqueID('MENU'),"\Pdummi");
-
- switch (i) {
- case 0:
- fontList = NULL;
- theLHP = &fontList;
- SetPt(&lOffset,10,10);
- iCount = CountResources('FONT');
- rowsVis = 6;
- if (iCount > 0)
- AddResMenu(dummyMH,'FONT');
- break;
-
- case 1:
- stylList = NULL;
- theLHP = &stylList;
- iCount = STYLcount;
- rowsVis = 6;
- SetPt(&lOffset,125,10);
- AppendMenu(dummyMH,"\PPlain;Bold;Italic;Underline;Outline;Shadow;Condense;Extend");
- break;
-
- case 2:
- sizeList = NULL;
- theLHP = &sizeList;
- iCount = SIZEcount;
- rowsVis = 5;
- SetPt(&lOffset,240,10);
- AppendMenu(dummyMH,"\P9 point;10 point;12 point;14 point;18 point;24 point;36 point");
- break;
-
- case 3:
- justList = NULL;
- theLHP = &justList;
- iCount = JUSTcount;
- rowsVis = 3;
- SetPt(&lOffset,355,10);
- AppendMenu(dummyMH,"\PLeft;Center;Right");
- break;
- }
-
- if ((iCount < 1) || (ResError() != noErr))
- return(FALSE);
- SetPt(&cSize,TEXTcellH,TEXTcellV);
- stat = LMMenuList(dummyMH,theLHP,wPtr,&lOffset,&cSize,iCount,rowsVis);
- if (dummyMH != NULL)
- DisposeMenu(dummyMH);
- if (stat == FALSE) {
- if (*theLHP != NULL)
- LDispose(*theLHP);
- *theLHP = NULL;
- }
- }
-
- if (stylList != NULL)
- (**stylList).selFlags = lUseSense | lNoNilHilite | lNoExtend;
-
- return(stat);
- }
-
- int ShowEdOpts()
- {
- if (GetEdOpts(FrontWindow()) == FALSE)
- return(FALSE);
-
- ShowWindow(edoptWP);
- SelectWindow(edoptWP);
- SetPort(edoptWP);
- /* InvalRect(&(edoptWP->portRect)); */
- }
-
- Boolean HndlEDOwindow()
- {
- EventRecord anEvent;
- WindowPtr whichWindow;
- ControlHandle whichControl;
- Point tPoint,tCell;
- ListHandle theLH;
- Boolean stat;
-
- ShowEdOpts();
- UpdateEdoptWindow(edoptWP);
-
- do {
- do {
- SystemTask();
- } while (!GetNextEvent(everyEvent,&anEvent));
-
- if (anEvent.what == mouseDown) {
- FindWindow(pass(anEvent.where),&whichWindow);
- if (whichWindow != edoptWP)
- SysBeep(10);
- else {
- tPoint = anEvent.where;
- GlobalToLocal(&tPoint);
-
- if (PtInEOLists(pass(tPoint),&theLH) == TRUE) {
- LClick(pass(tPoint),anEvent.modifiers,theLH);
- if (theLH == stylList) {
- SetPt(&tCell,0,0);
- if (LGetSelect(FALSE,&tCell,theLH) == TRUE) {
- LMSelectAll(theLH,FALSE);
- SetPt(&tCell,0,0);
- LSetSelect(TRUE,pass(tCell),theLH);
- }
- }
- }
- else {
- FindControl(pass(tPoint),whichWindow,&whichControl);
- if (whichControl == edoptWPB1) {
- HideWindow(edoptWP);
- return(TRUE);
- }
- if (whichControl == edoptWPB2) {
- HideWindow(edoptWP);
- return(FALSE);
- }
- }
- }
- }
- } while (TRUE);
- }
-
- Boolean PtInEOLists(lPoint,anLH)
- Point lPoint;
- ListHandle *anLH;
- {
- int i;
-
- for (i=0; i<4; i++) {
- switch (i) {
- case 0: *anLH = fontList; break;
- case 1: *anLH = stylList; break;
- case 2: *anLH = sizeList; break;
- case 3: *anLH = justList; break;
- }
-
- if (LMFindList(pass(lPoint),*anLH) > inDesk)
- return(TRUE);
- }
-
- *anLH = NULL;
- return(FALSE);
- }
-
-
- Boolean GetEdOpts(wPtr)
- WindowPtr wPtr;
- {
- WData WD;
- Point tCell;
- int cellLen,cellFNum,i;
- int theFont,theStyles,theSize;
- char fontName[256];
-
- GetWData(wPtr,&WD);
- if (!ValidWData(&WD) || (WD.TEH == NULL))
- return(FALSE);
-
- LMSelectAll(fontList,FALSE);
- LMSelectAll(stylList,FALSE);
- LMSelectAll(sizeList,FALSE);
- LMSelectAll(justList,FALSE);
-
- /* get font info and update the fontList */
- theFont = (**(WD.TEH)).txFont;
- if (theFont == applFont) {
- SetPt(&tCell,0,0);
- if (LSearch("Geneva",6,NULL,&tCell,fontList) == TRUE)
- LSetSelect(TRUE,pass(tCell),fontList);
- }
- else {
- for (i=0; i < (**fontList).dataBounds.bottom; i++) {
- SetPt(&tCell,0,i);
- cellLen = 256;
- LGetCell(&(fontName[1]),&cellLen,pass(tCell),fontList);
- fontName[0] = (unsigned char)cellLen;
- GetFNum(fontName,&cellFNum);
- if (cellFNum == theFont) {
- LSetSelect(TRUE,pass(tCell),fontList);
- break;
- }
- }
- }
- if (!PtInRect(pass(tCell),&((**fontList).visible)))
- LAutoScroll(fontList);
-
- /* get style info and update the styleList */
- theStyles = (**(WD.TEH)).txFace;
- if (theStyles == 0) {
- SetPt(&tCell,0,0);
- LSetSelect(TRUE,pass(tCell),stylList);
- }
- else {
- for (i=0; i < (STYLcount-1); i++)
- if (((int)1 << i) & theStyles) {
- SetPt(&tCell,0,i+1);
- LSetSelect(TRUE,pass(tCell),stylList);
- }
- }
-
- /* get size info and update the sizeList */
- theSize = (**(WD.TEH)).txSize;
- if (theSize == 0) {
- SetPt(&tCell,0,0);
- if (LSearch("12 point",8,NULL,&tCell,sizeList) == TRUE)
- LSetSelect(TRUE,pass(tCell),sizeList);
- }
- else {
- for (i=0; i<SIZEcount; i++)
- if (theSize == TESizes[i]) {
- SetPt(&tCell,0,i);
- LSetSelect(TRUE,pass(tCell),sizeList);
- break;
- }
- }
- if (!PtInRect(pass(tCell),&((**sizeList).visible)))
- LAutoScroll(sizeList);
-
- /* get justification info and update the justList */
- switch ((**(WD.TEH)).just) {
- case teJustLeft: SetPt(&tCell,0,0); break;
- case teJustCenter: SetPt(&tCell,0,1); break;
- case teJustRight: SetPt(&tCell,0,2); break;
- default: SetPt(&tCell,0,0); break;
- }
- LSetSelect(TRUE,pass(tCell),justList);
-
- return(TRUE);
- }
-
-
- Boolean SetEdOpts(wPtr)
- WindowPtr wPtr;
- {
- WData WD;
- GrafPtr savePort;
- FontInfo fInfo;
- Point tCell;
- int cellLen,cellFNum;
- char fontName[256];
-
- GetWData(wPtr,&WD);
- if (!ValidWData(&WD) || (WD.TEH == NULL))
- return(FALSE);
-
- SetCursor(*(GetCursor(watchCursor)));
-
- /* get fontList selection and update the edit window */
- SetPt(&tCell,0,0);
- (**(WD.TEH)).txFont = 0;
- if (LGetSelect(TRUE,&tCell,fontList) == TRUE) {
- cellLen = 256;
- LGetCell(&(fontName[1]),&cellLen,pass(tCell),fontList);
- fontName[0] = (unsigned char)cellLen;
- GetFNum(fontName,&((**(WD.TEH)).txFont));
- }
-
- /* get styleList selection(s) and update the edit window */
- SetPt(&tCell,0,1);
- (**(WD.TEH)).txFace = 0;
- while (LGetSelect(TRUE,&tCell,stylList) == TRUE) {
- (**(WD.TEH)).txFace |= (int)1 << (tCell.v-1);
- LNextCell(TRUE,TRUE,&tCell,stylList);
- }
-
- /* get sizeList selection and update the edit window */
- SetPt(&tCell,0,0);
- (**(WD.TEH)).txSize = 0;
- if (LGetSelect(TRUE,&tCell,sizeList) == TRUE)
- (**(WD.TEH)).txSize = TESizes[tCell.v];
-
- /* get justList selection and update the edit window */
- SetPt(&tCell,0,0);
- (**(WD.TEH)).just = teJustLeft;
- if (LGetSelect(TRUE,&tCell,justList) == TRUE)
- switch (tCell.v) {
- case 0: (**(WD.TEH)).just = teJustLeft; break;
- case 1: (**(WD.TEH)).just = teJustCenter; break;
- case 2: (**(WD.TEH)).just = teJustRight; break;
- default: (**(WD.TEH)).just = teJustLeft; break;
- }
-
- /* update the grafPort */
- GetPort(&savePort);
- SetPort(wPtr);
-
- TextFont((**(WD.TEH)).txFont);
- TextFace((**(WD.TEH)).txFace);
- TextSize((**(WD.TEH)).txSize);
-
- /* update the TextEdit record */
- GetFontInfo(&fInfo);
- (**(WD.TEH)).fontAscent = fInfo.ascent;
- (**(WD.TEH)).lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- TECalText(WD.TEH);
- TESetScrollRange(wPtr);
-
- InvalRect(&(wPtr->portRect));
- SetPort(savePort);
-
- /* we're back, live... */
- InitCursor();
-
- return(TRUE);
- }
-
-
- int UpdateEdoptWindow(wPtr)
- WindowPtr wPtr;
- {
- GrafPtr savePort;
- Rect tRect;
-
- GetPort(&savePort);
- SetPort(wPtr);
- BeginUpdate(wPtr);
- if (fontList != NULL) {
- LUpdate(((GrafPtr)wPtr)->visRgn,fontList);
- tRect = (**fontList).rView;
- InsetRect(&tRect,-1,-1);
- FrameRect(&tRect);
- }
- if (stylList != NULL) {
- LUpdate(((GrafPtr)wPtr)->visRgn,stylList);
- tRect = (**stylList).rView;
- InsetRect(&tRect,-1,-1);
- FrameRect(&tRect);
- }
- if (sizeList != NULL) {
- LUpdate(((GrafPtr)wPtr)->visRgn,sizeList);
- tRect = (**sizeList).rView;
- InsetRect(&tRect,-1,-1);
- FrameRect(&tRect);
- }
- if (justList != NULL) {
- LUpdate(((GrafPtr)wPtr)->visRgn,justList);
- tRect = (**justList).rView;
- InsetRect(&tRect,-1,-1);
- FrameRect(&tRect);
- }
- EndUpdate(wPtr);
- DrawControls(wPtr);
- SetPort(savePort);
- }
-
-
- void KillEdOpts()
- {
- if (fontList != NULL)
- LDispose(fontList);
- if (stylList != NULL)
- LDispose(stylList);
- if (sizeList != NULL)
- LDispose(sizeList);
- if (justList != NULL)
- LDispose(justList);
-
- KillWindow(edoptWP);
-
- edoptWP = NULL;
- edoptWPB1 = NULL;
- edoptWPB2 = NULL;
-
- fontList = NULL;
- stylList = NULL;
- sizeList = NULL;
- justList = NULL;
- }
-